package com.cloud.freeflow.api.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.freeflow.api.bean.WfActDef;
import com.cloud.freeflow.api.entity.BizType;
import com.cloud.freeflow.api.entity.ProcDef;
import com.cloud.freeflow.api.entity.ProcPart;
import com.cloud.freeflow.api.service.FreeflowInterfaceService;

@RestController
@RequestMapping("freeflow/api/interface")
public class FreeflowInterfaceController {

	@Autowired
	private FreeflowInterfaceService freeflowInterfaceService;

	/**
	 * 获取指定业务下的流程
	 * 
	 * @param bizId
	 * @return
	 */
	@RequestMapping("listprocbybiz")
	public List<ProcDef> listProcDefs(Long bizId) {
		return freeflowInterfaceService.listProcDefs(bizId);
	}

	/**
	 * 获取指定环节下的参与者
	 * 
	 * @param actDefId
	 * @return
	 */
	@RequestMapping("loadpartsbyactdef")
	public List<ProcPart> loadPartsByActDef(long actDefId) {
		return freeflowInterfaceService.listActParts(actDefId);
	}

	/**
	 * 获取流程参与者
	 * 
	 * @param procDefId
	 * @return
	 */
	@RequestMapping("loadpartsbyprocdef")
	public List<ProcPart> loadPartsByProcDef(long procDefId) {
		return freeflowInterfaceService.listProcParts(procDefId);
	}

	/**
	 * 获取指定业务下的流程、环节节点、参与者
	 * 
	 * @param bizId
	 * @return
	 */
	@RequestMapping("loadprocactparts")
	public List<ProcDef> loadProcActParts(int bizId) {
		return freeflowInterfaceService.loadProcActParts(bizId);
	}

	/**
	 * 根据参与者和流程编码获取开始节点
	 * 
	 * @param procDefId
	 * @param parts
	 * @return
	 */
	@RequestMapping("loadstartactbyprocandpart")
	public WfActDef loadStartActByProcAndPart(long procDefId, String parts) {
		return freeflowInterfaceService.loadStartActByProcAndPart(procDefId, parts);
	}

	/**
	 * 获取环节定义信息
	 * 
	 * @param actDefId
	 * @return
	 */
	@RequestMapping("loadactdef")
	public WfActDef loadActDefById(long actDefId) {
		return freeflowInterfaceService.loadActDefById(actDefId);
	}

	/**
	 * 获取流转的下一个环节
	 * 
	 * @param actDefId
	 * @return
	 */
	@RequestMapping("searchnextactdefs")
	public List<WfActDef> searchNextActDefs(Long actDefId) {
		return freeflowInterfaceService.searchNextActDefs(actDefId);
	}

	/**
	 * 加载流程下得全部环节
	 * 
	 * @param procDefId
	 * @return
	 */
	@RequestMapping("loadactdefbyproc")
	public List<WfActDef> loadActDefByProc(Long procDefId) {
		return freeflowInterfaceService.loadActDefByProc(procDefId);
	}

	/**
	 * 加载自定义业务列表
	 * 
	 * @return
	 */
	@RequestMapping("listcustombiz")
	public List<BizType> listCustomBizType() {
		return freeflowInterfaceService.listCustomBizType();
	}
	
	/**
	 * 创建自定义业务
	 * 
	 * @param bizType
	 * @return
	 */
	@RequestMapping("addcustombiz")
	public Long addCustomBiz(Integer bizId, String bizName) {
		return freeflowInterfaceService.createCustomBiz(bizId, bizName);
				
	}
}
